﻿<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>排故工艺规程数据上传</title>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <link rel="stylesheet" href="/InSiteWebApplication/Content/webuploader/webuploader.css" />
</head>
<body>
    <div id="divMain">
        <div class="panelSection">
            <div class="easyui-panel " title="结果区域" style="padding: 3px;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="background: #fff; margin: 3px 0px 3px 3px;">
                    <button id="btnSave" type="button" class="easyui-linkbutton" style="width: 120px;
                        height: 26px">
                        保存上传工艺</button>
                    <a href="" style="float: right">
                        下载导入模板</a>
                </div>
                <div style="background: #fff; margin: 3px 0px 3px 3px;">
                    <table id="dgWorkflow" class="easyui-datagrid" style="width: 100%; height: 100px"
                        data-options="rownumbers:true,fitColumns:true">
                    </table>
                    <div style="clear: both">
                    </div>
                </div>
                <div style="background: #fff; margin: 3px 0px 3px 3px;">
                    <table id="dgSpec" class="easyui-datagrid" style="width: 100%; height: 700px" data-options="rownumbers:true,fitColumns:true,singleSelect:true">
                    </table>
                    <div style="clear: both">
                    </div>
                </div>
            </div>
        </div>
        <div class="panelSection">
            <div class="easyui-panel " title="导入区域" style="padding: 3px;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="float: left;" id="uploadSec">
                    <form id="fm" method="post" enctype="multipart/form-data" style="margin: 0;" action="">
                    <div style="margin-left: 5px">
                        <input id='action' type="hidden" name="action" value="UploadWorkflowExcel" />
                        <input id='upfile' class="easyui-filebox" name="file1" data-options="buttonText:'选择文件'"
                            style="width: 350px; height: 24px" />
                    </div>
                    </form>
                </div>
                <div style="float: left">
                    <button id="sub" class="easyui-linkbutton" iconcls="icon-page" onclick="page.uploadDocFile()"
                        style="height: 24px; margin-left: 10px">
                        预览文件</button>
                    <span style="color: red; font-weight: bold; margin-left: 10px;">内部系统，严禁上传涉密信息</span>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script type="text/javascript" src="/InSiteWebApplication/Content/webuploader/webuploader.js"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    /*
    *主页面
    */
    var page = {
        rootPath: getRootPath(), //网站根路径
        url: getRootPath() + '/Ashx/WorkflowBaseFileUploadHandler.ashx', //后台处理地址
        init: function () {
            page.bind();
        },
        bind: function () {
            //上传工艺列表加载
            $("#dgWorkflow").datagrid({
                columns: [[
          { field: 'ProductName', title: '件号', width: 150 },
          { field: 'PartRevID', title: '设计图版次', width: 60 },
          { field: 'WorkflowName', title: '工艺规程', width: 180 },
          { field: 'WorkflowRev', title: '工艺版本', width: 60 },
          { field: 'WorkflowFactoryName', title: '分厂', width: 100 }
        ]]
            });
            //上传工艺列表加载
            $("#dgSpec").datagrid({
                columns: [[
          { field: 'SpecNo', title: '工序号', width: 60 },
          { field: 'SpecRev', title: '工序版本', width: 60 },
          { field: 'OpDesc', title: '工序名', width: 80 },
          { field: 'SpecDesc', title: '工序内容', width: 180 },
          { field: 'ApsMakeTime', title: '排产加工工时', width: 60 },
          { field: 'ApsResource', title: '排产设备', width: 80 },
          { field: 'SpecFactoryName', title: '分厂', width: 80 },
          { field: 'SpecType', title: '工序类型', width: 80 },
          { field: 'RealFileName', title: '附件', width: 100 },
          { field: 'OperaArea', title: '操作', width: 50, formatter: function (value, row, index) {
              return "<form id='specFile" + index + "' method='post' enctype='multipart/form-data' style='margin: 0;'>" +
                        "<input id='action' type='hidden' name='action' value='UploadSpecAttachFiles' />" +
                        "<input type='file' name='file' onchange='page.uploadSpecDocFile(" + index + ")' style='width: 70px; height: 24px' />" +
                        '</form>';
          }
          }
        ]]
            });
            //保存按钮
            $("#btnSave").on("click", function () {
                page.saveWorkFlowData();
            });
        },
        //上传工艺文件
        uploadDocFile: function () {
            page.clearPage(true, false);
            $.messager.progress({ text: '', msg: '处理中...' });
            $('#fm').form('submit', {
                url: page.url,
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (result) {
                    $.messager.progress('close');
                    var res = JSON.parse(result);
                    if (res.Result) {
                        $("#dgWorkflow").datagrid('loadData', { rows: res.DBDataSet.dtPageWorkflow });
                        $("#dgSpec").datagrid('loadData', { rows: res.DBDataSet.dtPageSpec });
                    }
                    $("#upfile").filebox("clear"); //清除上传控件
                    displayMessage(res.Message, res.Result);
                },
                error: function () {
                    $.messager.progress('close');
                }
            });
        },
        //上传工序附件
        uploadSpecDocFile: function (index) {
            $("#specFile" + index).form('submit', {
                url: page.url,
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (result) {
                    $.messager.progress('close');
                    var res = JSON.parse(result);
                    if (res.Result) {
                        $("#dgSpec").datagrid("updateRow", { index: index, row: { FileName: res.ReturnData[0], RealFileName: res.ReturnData[1]} });
                        $("#dgSpec").datagrid("acceptChanges");
                    }
                    displayMessage(res.Message, res.Result);
                },
                error: function () {
                    $.messager.progress('close');
                }
            });
        },
        //保存工艺路线
        saveWorkFlowData: function (datas) {
            var dtWorkflow = $("#dgWorkflow").datagrid("getRows");
            var dtSpec = $("#dgSpec").datagrid("getRows");
            if (dtWorkflow.length === 0 || dtSpec.length === 0) {
                displayMessage("没有数据可以保存", false);
                return;
            }
            page.post(page.url, { action: "SaveWorkflowDatas", dtWorkflow: JSON.stringify(dtWorkflow), dtSpec: JSON.stringify(dtSpec) }, false, function (result) {
                if (result.Result) {
                    page.clearPage(true, true);
                }
                displayMessage(result.Message, result.Result);
            });
        },
        //清除页面数据
        clearPage: function (isList, isUpload) {
            if (isList) {
                clearEasyuiDataGrid("dgWorkflow"); //清空列表
                clearEasyuiDataGrid("dgSpec"); //清空列表
            }
            if (isUpload) {
                $("#upfile").filebox("clear"); //清除上传控件
            }
        },
        //post数据（路径，参数，是否异步，成功返回方法）
        post: function (url, param, async, callback) {
            $.ajax({
                type: "Post",
                url: url,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                    $("body").find(".easyui-linkbutton").each(function () {
                        $(this).linkbutton('enable');
                    });
                }
            })
        }
    }
    /*
    *页面加载入口
    */
    $(function () {
        page.init();
        $("#fm .l-btn-text").css("margin-top", "3px");
    });
</script>
